package com.fyzk.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.tyjc.lottery.R;

public class GetAwardDialog extends Dialog implements View.OnClickListener {
    private TextView awardTxt;
    private TextView submitTxt;

    private Context mContext;
    private OnConfirmListener listener;
    private String positiveName;
    private String award;

    public GetAwardDialog(Context context, OnConfirmListener listener) {
        super(context, R.style.commonDialog);
        this.mContext = context;
        this.listener = listener;
    }

    public GetAwardDialog setAward(String award) {
        this.award = award;
        return this;
    }

    public GetAwardDialog setPositiveButton(String name) {
        this.positiveName = name;
        return this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_get_award);
        setCanceledOnTouchOutside(false);
        initView();
    }

    private void initView() {
        awardTxt = findViewById(R.id.award);
        submitTxt = findViewById(R.id.submit);
        submitTxt.setOnClickListener(this);

        if (!TextUtils.isEmpty(positiveName)) {
            submitTxt.setText(positiveName);
        }

        if (!TextUtils.isEmpty(award)) {
            awardTxt.setText(award);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.submit:
                if (listener != null) {
                    listener.onClick(this, true);
                }
                this.dismiss();
                break;
        }
    }

    public interface OnConfirmListener {
        void onClick(Dialog dialog, boolean confirm);
    }
}
